package Chapter12.demo03;

public class Join implements Runnable {
    Thread driver,worker,administrator;
    public void setThread(Thread ... t) {
        driver=t[0];
        worker=t[1];
        administrator=t[2];
    }
    public void run() {
        if(Thread.currentThread()==driver) {
            System.out.println(driver.getName()+"等待"+
                    worker.getName()+"搬运货物");
            try{  worker.start();
                worker.join();            //当前线程开始等待worker结束
            }
            catch(InterruptedException e){}
            System.out.println(driver.getName()+
                    "启动车辆，离开");
        }
        else if(Thread.currentThread()==worker) {
            System.out.println(worker.getName()+"等待"+administrator.getName()+"打开仓库大门");
            try{  administrator.start();administrator.join();
            }
            catch(InterruptedException e){}
            System.out.println(worker.getName()+"装载货物完毕");
        }
        else if(Thread.currentThread()==administrator) {
            System.out.println(administrator.getName()+"正在打开大门");
            try { Thread.sleep(2000);
            }
            catch(InterruptedException e){}
            System.out.println(administrator.getName()+"已经打开仓库大门。");
        }
    }
}
